Right now we'll use the decision tree algorithm to classify some instances in Iris dataset.
First at all, let's import tree class and other classes.
In [1]:
from sklearn import datasets
from sklearn import metrics
from sklearn.tree import DecisionTreeClassifier
We'll import Iris dataset and put inside the object called dataset
In [2]:
dataset = datasets.load_iris()
After that, let's instance out model calling the method Classifier.
In [3]:
model = DecisionTreeClassifier()
In [4]:
model.fit(dataset.data, dataset.target)
Out[4]:
In [5]:
expected = dataset.target
In [6]:
predicted = model.predict(dataset.data)
In [7]:
print(metrics.classification_report(expected, predicted))
In [8]:
print(metrics.confusion_matrix(expected, predicted))
In [9]:
predicted
Out[9]:
In [ ]: